package topcoder;

import java.text.DecimalFormat;
import java.text.NumberFormat;

public class RotatedClock {

	public String getEarliest(int hourHand, int minuteHand){
		
		NumberFormat formatter = new DecimalFormat("00");
		
		for(int i = 0; i <= 11; i++){
			double min = minuteHand/30.0*5;
			if(minuteHand == 360)
				min = 0;
			int hr = hourHand/30;
			if(hourHand == 360)
				hr = 0;
			
			if(min+hr*60 == hourHand*2)
				return "" + formatter.format(hr) + ":" + formatter.format(min);
			
			minuteHand += 30;
			if(minuteHand>=360)
				minuteHand -= 360;
			
			hourHand += 30;
			if(hourHand>=360)
				hourHand -= 360;
		}
		
		return "";
	}
	
	public static void main(String[] args) {
		RotatedClock rc = new RotatedClock();
		System.out.println(rc.getEarliest(70, 300));
	}
}
